<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:h="http://java.sun.com/jsf/html"
	  xmlns:t="http://myfaces.apache.org/tomahawk"
	  xmlns:rich="http://richfaces.org/rich" 
	  >

<h:head>
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<meta http-equiv="Cache-Control" content="no-store" />
	<meta http-equiv="Expires" content="0" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

	<title><ui:insert name="title">mDMS-Medical Document System Managment</ui:insert></title>

	<link rel="stylesheet" type="text/css"
		href="#{facesContext.externalContext.requestContextPath}/static/layout#{userMBean.userLayoutId}/css/login.css"
		media="all" />

</h:head>

<h:body>


	<h:form id="login_form">
		<f:loadBundle basename="com.mdms.utils.MDmsRessources"
			var="vresources" />


		<div id="mainDiv" class="mainDiv">
			<div class="fieldDiv">
				<table cellpadding="10">
					<tr>
						<td><h:outputText styleClass="textField"
								value="#{vresources['userLogin.login']}" /></td>
						<td><h:inputText styleClass="textBox" id="login"
								value="#{userMBean.login}" /></td>
					</tr>
				</table>
			</div>

			<div class="fieldDiv">
				<table cellpadding="10">
					<tr>
						<td><h:outputText styleClass="textField"
								value="#{vresources['userLogin.password']}" /></td>
						<td><h:inputSecret styleClass="textBox" id="password"
								value="#{userMBean.password}" /></td>
					</tr>
				</table>
				<h:inputHidden id="hash" value="#{userMBean.md5Password}" />
			</div>
			
			<div id="innerDiv" class="innerDiv"></div>

			<div class="innerButtonDiv">
			<h:commandButton styleClass="loginButton" action="#{userMBean.loginUser}"
				onclick="if (!GetPasswd(this, false)) return true;"
				/>
				</div>
		</div>



		<script type="text/javascript"
			src="#{facesContext.externalContext.requestContextPath}/js/crypto312/rollups/md5.js" />
		<script type="text/javascript" language="JavaScript">
		var contextPath = '#{facesContext.externalContext.requestContextPath}';
		
		function GetPasswd(element, plainText) {

			var mainForm = element.form;
			if(mainForm==null){
				mainForm = document.getElementById('login_form');
			}
			var loginField = mainForm.elements[mainForm.id+':login'];
			var passField = mainForm.elements[mainForm.id+':password'];
			var hashField = mainForm.elements[mainForm.id+':hash'];
			var loginButton = mainForm.elements[mainForm.id+':loginButton'];
			
				
				if (loginField.value == "" || passField.value == "") {
					alert(unutf('#{messages['form.login.warn1']}'));
					return false;
				} else {
					if (plainText) {
						hashField.value = passField.value
					} else {
						var hash = CryptoJS.MD5(passField.value);
						passField.value="";
						hashField.value=hash;
					}
					// mainForm.elements['task'].value = 'LOGIN';
					// loginButton.disabled = true;
					return true;
				}
			
		}
		</script>
	</h:form>
</h:body>


</html>
